/*
 *  ifxdefs.hpp - Informix base definitions
 *
 *    Copyright (c) 2001-2006, Luxena Software Company. All rights reserved.
 *
 *  Purpose:
 *
 */

#ifndef __IFXDEFS_HPP__
#define __IFXDEFS_HPP__

#ifndef __cplusplus
#error This header requires a C++ compiler ...
#endif

#include <malloc.h>
#include <stdlib.h>
#include <memory>


#ifdef WIN32
#include <sqlhdr.h>
inline void ifx_setenv(const char *name, const char *value)
{
	int nameLength = strlen(name);
	int valueLength = strlen(value);

	char *entry = static_cast<char *>(alloca(nameLength + sizeof('=') + valueLength + sizeof('\0')));

	char *pos = entry;
	memcpy(pos, name, nameLength);
	*(pos += nameLength)++ = '=';
	memcpy(pos, value, valueLength);
	pos[valueLength] = '\0';

	ifx_putenv(entry);
}
#define freeSQLDA(sqlda)				SqlFreeMem(sqlda, SQLDA_FREE)
#define freeSimpleLOBuffer(pbuffer)		SqlFreeMem(pbuffer, STRING_FREE)
#else
#define ifx_setenv(name, value)			setenv(name, value, 1)
#define ifx_getenv(name)				getenv(name)
#define freeSQLDA(sqlda)				free(sqlda)
#define freeSimpleLOBuffer(buffer)		free(buffer)
#endif

#define IFX_NOT_IN_TRANSACTION			-255
#define IFX_SERVER_BUSY					-439
#define IFX_ALREADY_IN_TRANSACTION		-535
#define IFX_DATABASE_IN_CONNECT			-759
#define IFX_INVALID_TRANSACTION_STATE	-1800

#define IFX_COMMIT_RETAIN_FLAG			0x1000

#define IFX_DIRTY_READ					"DIRTY READ"
#define IFX_COMMITED_READ				"COMMITTED READ"
#define IFX_REPEATABLE_READ				"REPEATABLE READ"
#define IFX_CURSOR_STABILITY			"CURSOR STABILITY"
#define IFX_RETAIN_UPDATE_LOCKS			" RETAIN UPDATE LOCKS" // don't remove leading space

#define INTERVAL_AS_VARCHAR_LENGTH		28
#define INT8_AS_DECIMAL_PRECISION		20
#define FLOATING_DECIMAL_PRECISION		32
#define FLOATING_DECIMAL_SCALE			16


/////////////////////////////////////////////////////////////////////////////
// CInformixActivity - holder of some activity

struct CInformixActivity {
	virtual ~CInformixActivity () {}
};

typedef std::auto_ptr<CInformixActivity> CInformixActivityPtr;

#endif // __IFXDEFS_HPP__
